﻿using System;
using System.Diagnostics;
using System.Windows.Data;
using AEM.Controls;

namespace AEM.Converters
{
    internal class ValueToRectangleHeightConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // 获取传递过来的直方图控件实例的引用
            ObjectDataProvider provider = parameter as ObjectDataProvider;
            Histogram histogram = provider.ObjectInstance as Histogram;
            Debug.Assert(histogram != null);
            double number = (double)value;
            // 加一个0.9是不想让直方图数据的最大值顶到了直方图的最上层。
            double height= histogram.ActualHeight * 0.9 * number / (histogram.Maximum - histogram.Minimum);
            return height == 0 ? histogram.ActualHeight * 0.015 : height;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
